export default class mouse extends Laya.Script {
   /** @prop {name:mouse_type, tips:"老鼠类型", type:Int, default:1}*/
   
    constructor() { 
        super(); 
        this.mouse_type = 1;
        this.time_line = null;
        this.is_click = false;
    }
    
    onEnable() {
    }

    onDisable() {
    } 

    show_mouse(mgr,mouse_type,hole_index){
        this.game_mgr = mgr;
        this.hole_index = hole_index;
        this.mouse_type = mouse_type;
        this.owner.skin = "res/mouse_normal_"+this.mouse_type+".png";

        this.owner.scaleX = 0;
        this.owner.scaleY = 0;

        this.time_line = Laya.TimeLine.to(this.owner,{scaleX:1,scaleY:1},300);
        this.time_line.to(this.owner,{scaleX:0,scaleY:0},300,null,1000);

        this.time_line.on(Laya.Event.COMPLETE,this,function(){
            this.owner.removeSelf();
        });
        this.time_line.play(0,false);
    }
    onStart(){
        this.is_click = false;
      //  this.show_mouse(this.mouse_type);
    }

    play_hit_anim(){
        this.owner.skin = "res/mouse_hit_"+this.mouse_type+".png";
        if(this.time_line){
            this.time_line.destroy();
            this.time_line = null;
        }
        //this.time_line = Laya.TimeLine.to(this.owner,{scaleX:1,scaleY:1},300);
        this.time_line = Laya.TimeLine.to(this.owner,{scaleX:0,scaleY:0},300,null,500);

        this.time_line.on(Laya.Event.COMPLETE,this,function(){
            this.owner.removeSelf();
        });
        this.time_line.play(0,false);
    }

    onClick(){
        if(this.is_click){
            return;
        }
        this.is_click = true;
       this.play_hit_anim();
    //  console.log(this.mouse_type+"---"+this.hole_index);
        this.game_mgr.on_mouse_hit(this.mouse_type,this.hole_index);
    }
}